package cn.yh.springsecurity.controller;

import cn.yh.springsecurity.common.AjaxResult;
import cn.yh.springsecurity.controller.base.BaseController;
import cn.yh.springsecurity.domain.query.LoginBody;
import cn.yh.springsecurity.service.IUserService;
import cn.yh.springsecurity.utils.VerifyAuthorityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController extends BaseController {


    @Autowired
    private IUserService userService;
    @Autowired
    private VerifyAuthorityUtils verifyAuthorityUtils;

    @GetMapping("/test")
    public List<String> test(){
        return Arrays.asList("test1","test2");
    }


    @PostMapping("/login")
    public AjaxResult login(LoginBody loginBody){
        return userService.loginByUser(loginBody);
    }

    @PreAuthorize("@verifyAuthorityUtils.hasAnyPerms('employee')")
    @GetMapping("/employee")
    public AjaxResult employee(){
        return AjaxResult.success("员工管理");
    }

    @PreAuthorize("@verifyAuthorityUtils.hasAnyPerms('work')")
    @GetMapping("/work")
    public AjaxResult work(){
        return AjaxResult.success("上班");
    }

    @PreAuthorize("@verifyAuthorityUtils.hasAnyPerms('clock')")
    @GetMapping("/clock")
    public AjaxResult clock(){
        return AjaxResult.success("打卡");
    }

}
